﻿@using System.Web.Optimization
@using VocaDb.Web.Helpers;
@using R = ViewRes.Album;
@inherits VocaDb.Web.Code.VocaDbPage<VocaDb.Web.Models.Album.Create>

@{
	PageProperties.Title = R.CreateStrings.SubmitAlbum;
	ViewBag.Parents = new[] { 
		Html.ActionLink(ViewRes.SharedStrings.Albums, "Index")
	};	
}

<form action="@Url.Action("Create", "Album")" method="POST" data-bind="submit: submit">

	@Helpers.ValidationSymmaryDiv(R.CreateStrings.UnableToCreateAlbum)
																								
	<div class="row-fluid">
		<div class="span5 well well-transparent">

			<div class="editor-label">
				@ViewRes.EntryCreateStrings.Name
				@Helpers.RequiredField()
			</div>

			<div class="editor-field">
				@Html.ValidationMessage("Names")

				<table><tr><td class="formLabel">				
				@Html.LabelFor(m => m.NameOriginal)
				</td><td>
					 @Html.TextBoxForKnockout(m => m.NameOriginal, "textInput: nameOriginal, focusout: checkDuplicates", cssClass: "span12", maxLength: 255, size: 40)
				</td></tr>

				<tr><td class="formLabel">
				@Html.LabelFor(m => m.NameRomaji)
				</td><td>
					 @Html.TextBoxForKnockout(m => m.NameRomaji, "textInput: nameRomaji, focusout: checkDuplicates", cssClass: "span12", maxLength: 255, size: 40)
				</td></tr>
					
				<tr><td class="formLabel">
				@Html.LabelFor(m => m.NameEnglish)
				</td><td>
				 	@Html.TextBoxForKnockout(m => m.NameEnglish, "textInput: nameEnglish, focusout: checkDuplicates", cssClass: "span12", maxLength: 255, size: 40)
				</td></tr></table>
			</div>
			
			<div class="editor-label">
				@Html.LabelFor(m => m.DiscType)
			</div>
			<div class="editor-field">
				@Html.DiscTypeDropDownListFor(m => m.DiscType)
			</div>

			<div class="editor-label">
				<span>@R.CreateStrings.ArtistsInfo</span>
				@Helpers.RequiredField()
				<br />
				<span class="extraInfo">@BrandableStrings.Album.NewAlbumArtistDesc</span>
			</div>
			<div class="editor-field">
				@Html.ValidationMessage("Artists")
				<table>
					<tbody data-bind="foreach: artists">
						<tr>
							<td>
								<a data-bind="attr: { href: vdb.utils.EntryUrlMapper.details('Artist', id) }, text: name, artistToolTip: id"></a>
							</td>
							<td>
								<a data-bind="click: $parent.removeArtist" href="#" class="textLink removeLink">@ViewRes.SharedStrings.Remove</a>
							</td>
						</tr>
					</tbody>
				</table>
				<br />
				<input type="text" data-bind="artistAutoComplete: artistSearchParams" maxlength="128" placeholder="@ViewRes.SharedStrings.Search" class="span8" />
				@Html.HiddenForKnockout(m => m.Artists, "value: ko.toJSON(artists)")
			</div>
			
			<br />
			<button type="submit" data-bind="disable: submitting" class="btn btn-primary">@ViewRes.SharedStrings.Save</button>

		</div>

		<div class="span4">
			<div class="alert">
				@Html.Raw(BrandableStrings.Album.NewAlbumInfo)
			</div>			     
			<div class="alert alert-info">
				<p>@Html.Raw(R.CreateStrings.AlbumInfo2)</p>
				<p>@ViewRes.EntryCreateStrings.NoArtistsToName</p>
				<p>@ViewRes.EntryCreateStrings.NameHelp</p>				
			</div>
			
			@{ Html.RenderPartial("KnockoutPartials/_DuplicateEntriesMessage"); }
		</div>
		
	</div>
	
</form>

@section BodyScripts {
	@Scripts.Render("~/bundles/shared/edit", "~/bundles/Album/Create")
    <script type="text/javascript">

		$(function () {

        	var urlMapper = new vdb.UrlMapper('@RootPath');
        	var repoFactory = new vdb.repositories.RepositoryFactory(urlMapper, @LanguagePreferenceInt);
        	var albumRepo = repoFactory.albumRepository();
        	var artistRepo = repoFactory.artistRepository();

        	ko.applyBindings(new vdb.viewModels.AlbumCreateViewModel(albumRepo, artistRepo));

        });

</script>
}